package com.zoe.thread.th01_变量安全问题;

/**
 * @Author Zoe.Zhang
 * @Date: 2021/07/30
 * @Description 静态成员变量不安全，不管事单例还是多例
 */
public class StaticFiled_静态变量线程不安全 implements Runnable {
    static int ticket = 100;

    @Override
    public void run() {
        System.out.println(Thread.currentThread() + "已售出:" + ticket--);
    }
}

class Window {
    public static void main(String[] args) {
        StaticFiled_静态变量线程不安全 staticFiled = new StaticFiled_静态变量线程不安全();
        for (int i = 0; i < 100; i++) {
            new Thread(staticFiled).start();
        }
    }
}